package com.lyfei.ydc.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lyfei.ydc.domain.entity.Spu;
import com.lyfei.ydc.domain.vo.SpuVo;
import com.lyfei.ydc.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spu")
public class SpuController {
    @Autowired
    private SpuService spuService;

    @GetMapping("/detail/{id}")
    public SpuVo detail(@PathVariable Long id) {
        return spuService.detail(id);
    }

    @GetMapping("/by/category/{cid}")
    public IPage<Spu> getByCategoryId(@PathVariable Long cid,
                                      @RequestParam(name = "start", defaultValue = "0") Integer start,
                                      @RequestParam(name = "count", defaultValue = "10") Integer count) {

        return spuService.getByCategoryId(cid, start / count + 1, count);
    }
}
